package com.open.capacity.exam.controller;

import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.exam.service.QuestionService;
import com.open.capacity.exam.vo.QuestionsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
@Api(tags = "考题管理")
public class QuestionController {
    @Autowired
    private QuestionService examService;

    /**
     * 模糊查询考题
     * @param param
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "条件查询考题")
    public PageResult<QuestionsVo> findAll(QuestionsVo param){
        return examService.findAll(param);
    }

    /**
     * 添加考题
     * @param param
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加考题")
    public Result addQuestions(@RequestBody QuestionsVo param) {
        try {
            return  examService.addQuestions(param);
        } catch (ServiceException e) {
            throw new ControllerException(e.getMessage());
        }
    }

    /**
     * 修改考题
     * @param param
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "修改考题")
    public Result editQuestions(@RequestBody QuestionsVo param){
        return  examService.editQuestions(param);
    }

    /**
     * 获取所有考题阶段
     * @return
     */
    @GetMapping("/getStage")
    @ApiOperation(value = "获取所有阶段")
    public List<String> getStage(){
        return examService.getStage();
    }
}
